package com.huaqin.common;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class Util {
	

	/*
	 * 将配置文件中时间描述转化成分钟以 long 型数据返回
	 */
	public static long getVales(String time){

		if(time == null){
			return 0;
		}
		
		long value = 0;
		
		//分钟
//		if(){
//			
//		}
		
		return value;
	}

    public static void setBooleanPref(Context context, String name, boolean value) {
        SharedPreferences prefs = context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
        Editor ed = prefs.edit();
        ed.putBoolean(name, value);
        ed.commit();
    }
    
    public static boolean getIntPref(Context context, String name, boolean def) {
        SharedPreferences prefs = context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
        return prefs.getBoolean(name, def);
    }
	
    public static void setIntPref(Context context, String name, int value) {
        SharedPreferences prefs = context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
        Editor ed = prefs.edit();
        ed.putInt(name, value);
        ed.commit();
    }
    
    public static int getIntPref(Context context, String name, int def) {
        SharedPreferences prefs = context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
        return prefs.getInt(name, def);
    }
    
    public static void setLongPref(Context context, String name, long value) {
        SharedPreferences prefs = context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
        Editor ed = prefs.edit();
        ed.putLong(name, value);
        ed.commit();
    }
    
    public static long getLongPref(Context context, String name, long def) {
        SharedPreferences prefs = context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
        return prefs.getLong(name, def);
    }
    
    public static void setStringPref(Context context, String name, String value) {
        SharedPreferences prefs = context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
        Editor ed = prefs.edit();
        ed.putString(name, value);
        ed.commit();
    }
    
    public static String getStringPref(Context context, String name, String def) {
        SharedPreferences prefs = context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
        return prefs.getString(name, def);
    }
    
    public static boolean isNumber(char c){
		if((c >= '0' && c <= '9')){
			return true;
		}else{
			return false;
		}
	}

    public static boolean isCharacter(char c){
		if((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')){
			return true;
		}else{
			return false;
		}
	}

    public static boolean isUrlCharacter(char c){
		final String URL_SPECIAL_CHARACTER = ":/+?&%#.-_="; //URL特殊字符
	    	if(isCharacter(c) || URL_SPECIAL_CHARACTER.indexOf(c) > -1){
	        	return true;
	    	}
		return false;
	}
    
    public static boolean isLogicString(String bool){
    	return bool.equals("true") ? true : (bool.equals("false") ? true : false);
    }
    
    public static boolean isPhoneNumber(String str){
    	if(str != null){
    		String PHONE_PATTERN = "[*]?[*]?[0-9]{4,12}";
    		return str.matches(PHONE_PATTERN);
    	}
    	return false;
    }
    
    public static boolean isEmail(String str){
    	if(str != null){
    		String EMAIL_PATTERN = "[*]?[0-9,a-z,A-Z,_,-]{6,30}@[0-9,a-z]{2,8}.com[.]?[c]?[n]?";
    		return str.matches(EMAIL_PATTERN);
    	}
    	return false;
    }
    
    public static boolean isHttpUrl(String str){
    	if(str != null){
    		String HTTPS_PATTERN = "[*]?http://[0-9,a-z,A-Z,:,/,+,?,&,%,#,.,-,_,=]{6,80}";
    		return str.matches(HTTPS_PATTERN);
    	}
    	return false;
    }
    
    //Max 10
    public static boolean isTimeOrInterval(String str){
    	if(str != null){
    		String NUM_PATTERN = "[0-9,]{1,3}";
    		return str.matches(NUM_PATTERN);
    	}
    	return false;
    }
    
    
}
